package controller

import (
	"base/app/models"
	"github.com/gin-gonic/gin"
)

type LoginCtl struct {
}

var Login = LoginCtl{}

func (ctl *LoginCtl) Login(c *gin.Context) {
	var req models.User
	_ = c.ShouldBind(&req)
	var user models.User
	//查找是否有用户名和密码相同的用户
	models.Db.Where("username = ? and password = ?", req.Username, req.Password).First(&user)
	if user.Username == "" {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "用户名或密码错误",
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "登录成功",
		"data": user,
	})
}
